<template>
  <k-form-modal v-model="modalState.visible" width="720px" @submit="hide">
    <template #title>
      <div class="title-box">
        <div class="left">
          <span class="title base-text-ellipsis">{{ rowData.title }}</span>
          <span>的关联橱窗</span>
        </div>
        <span class="tip">*非官方数据，仅供参考</span>
      </div>
    </template>
    <KTable v-if="modalState.visible" v-loading="state.loading" v-bind="tableState" v-on="tableEvent">
      <template #cover="{ row }">
        <div class="info">
          <el-image :src="row.avatar" class="img" style="border-radius: 50%" alt="cover" />
          <div class="right">
            <div class="title-box">
              <div class="title base-text-ellipsis">{{ row.nick_name }}</div>
            </div>
            <p class="name base-text-ellipsis">{{ row.display_id }}</p>
          </div>
        </div>
      </template>
    </KTable>
  </k-form-modal>
</template>

<script setup lang='ts'>
import { ref } from 'vue';
import { useFormModal } from '@crud/index';
import { useTableList } from '../hooks/use-relative-table';
defineOptions({
  name: 'KgjJuejinRelativeListModal'
});
const { state, tableState, tableEvent, ...methods } = useTableList();
const rowData = ref<any>({});
const { state: modalState, show, hide } = useFormModal({
  onShow: (mode = 0, data: any) => {
    tableState.value.data = [];
    rowData.value = data;
    if (data) {
      state.params = {
        productId: data.product_id
      };
      methods.getList();
    }
  }
});
defineExpose({
  show
});
</script>
<style lang="scss" scoped>
.title-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 400;
  color: #909399;

  .left {
    display: flex;
    align-items: center;
  }

  .title {
    flex: 1;
    max-width: 108px;
    height: 26px;
    font-size: 18px;
    line-height: 26px;
    color: #303133;
  }

  .tip {
    margin-right: 10px;
    color: #C0C4CC;
  }
}

.info {
  display: flex;
  align-items: center;
  cursor: pointer;

  .img {
    flex-shrink: 0;
    width: 47px;
    height: 47px;
  }

  .right {
    flex: 1;
    margin-left: 8px;
    overflow: hidden;

    .title-box {
      display: flex;
      align-items: center;
      color: #303133;
    }

    .title {
      min-width: 0;
      height: 23px;
      overflow: hidden;
      font-size: 14px;
      font-weight: 400;
      line-height: 23px;
      color: #303133;
    }

    .name {
      font-size: 12px;
      font-weight: 400;
      line-height: 20px;
      color: #909399;
    }
  }

  &:hover {
    .right {
      .title-box,
      .title {
        color: #4975e9;
      }
    }
  }
}
</style>
